<?php


namespace app\common\service\coupon;


use app\common\service\coupon\sync_channel\Base;
use app\common\service\coupon\sync_channel\JutuikeChannel;
use app\model\Agent;
use app\model\BaseSupplier;
use think\Exception;
use app\common\service\coupon\sync_channel\YiQiDaChannel;
use app\common\service\coupon\sync_channel\JingChongChannel;

class CouponSyncService
{

    //渠道
    const CHANNEL_JUTUIKE = JutuikeChannel::class;
    const CHANNEL_YIQIDA = YiQiDaChannel::class;
    const CHANNEL_JINGCHONG = JingChongChannel::class;

    /**
     * @var BaseSupplier $suppplier
     */
    public $suppplier;


    public function sync($channel = self::CHANNEL_JUTUIKE)
    {
        /**
         * @var Base $service
         */
        $service = new $channel;

        if (empty($service->supplier)) throw new Exception('接口供应商信息残缺$service->supplier');


        /**
         * @var JutuikeChannel 聚推客同步逻辑
         */
        foreach (['Cate', 'Brand', 'Product','Type','ChannelProduct'] as $function) {
            $get_name = 'get' . $function;
            $save_name = 'save' . $function;
            $service->{$get_name}();
            $service->{$save_name}();
        }
    }


}